<?php

namespace App\Http\Controllers\Api;

use App\Support\Response;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Log;

class BaseController
{
    protected function success($data = null, $msg = "success", $code = 200): JsonResponse
    {
        if($data instanceof  LengthAwarePaginator){
            $data=[
                'items'=>$data->items(),
                'current_page'=>$data->currentPage(),
                'last_page'=>$data->lastPage(),
                'total'=>$data->total()
            ];

        }
        return Response::create($code, $msg, $data);
    }

    protected function fail($msg = 'fail', $code = 400, $data = null): JsonResponse
    {
        return Response::create($code, $msg, $data);
    }
}
